package pt.fct.mpc.rfbul.misc;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import android.net.wifi.ScanResult;

public class PositionDevice
{
	public String BSSID;
	public String SSID;
	public int signal;
	
	public PositionDevice(String bssid, String ssid, int signal)
	{
		this.BSSID = bssid;
		this.SSID = ssid;
		this.signal = signal;
	}
	
	public PositionDevice(ScanResult result)
	{
		this(result.BSSID, result.SSID, result.level);
	}
	
	static public Set<PositionDevice> 
	getSetBySSID(Collection<ScanResult> results, String ssid)
	{
		Set<PositionDevice> devices = new HashSet<PositionDevice>();
		for (ScanResult r : results)
		{
			if (r.SSID.compareToIgnoreCase(ssid) != 0)
				continue;
			
			devices.add(new PositionDevice(r));
		}
		
		return devices;
	}
	

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((BSSID == null) ? 0 : BSSID.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		PositionDevice other = (PositionDevice) obj;
		if (BSSID == null)
		{
			if (other.BSSID != null) return false;
		} else if (!BSSID.equals(other.BSSID)) return false;
		return true;
	}
	
	
}
